package net.bwie.jtp.app.udf;

import ch.hsr.geohash.GeoHash;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDF;

@Description(
        name="convert_geohash",
        value = "_FUNC_(latitude, longitude, precision) - returns a geohash code"
)
public class ConvertGeoHash extends UDF {
    public String evaluate(double latitude,double longitude,int precision){
       // 1创建GeoHash对象，指定经纬度和精度
        String geoHash = GeoHash.geoHashStringWithCharacterPrecision(latitude, longitude, precision);
        // 2将GeoHash对象转换为Base32编码的字符串
        return geoHash;
    }

    public static void main(String[] args) {
        System.out.println(
                new ConvertGeoHash().evaluate(35.46847397820407, 119.36278007513695, 6)
        );
    }
}